package com.dp.struts2.yc.news;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;

import org.apache.log4j.Logger;
import org.apache.struts2.util.ServletContextAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.dp.pojo.NewsVo;
import com.dp.pub.BasePageAction;
import com.dp.pub.SysProperty;
import com.dp.service.jdc.ChannelServiceImpl3;
import com.dp.service.jdc.IndexServiceImpl;
import com.dp.service.jdc.NewsServiceImpl;
import com.dp.vo.TChannels;
/**
 * 新闻信息ACTION
 * 
 */
@Controller
@Scope("session")
public class YcimgnewsAction extends BasePageAction implements ServletContextAware {
	/**
	 * 
	 */
	private static Logger logger = Logger.getLogger(YcimgnewsAction.class);
	private List<TChannels> navChannels ;
	private List<List<TChannels>> nav2Channels;
	private String navOnChannelId;
	
    /**
     * 左侧菜单栏栏目列表
     */
    private List<TChannels> channelsList;
    /**
     *新闻所属的上一级栏目 
     */
    private TChannels newsTopChannel;

    /**
     *新闻所属的最顶级栏目
     */
    private TChannels leftTopChannel;
    
    private NewsVo news;//新闻内容
    
    private String channelId;
    private String contentId;
    
   
    @Autowired
    private ChannelServiceImpl3 channelService;
    @Autowired
    private IndexServiceImpl indexService;
    
    @Autowired
	private NewsServiceImpl newsService;
    
	/**进入新闻内容页面
	 * @author 霍
	 * @param channelNameList//新闻所属栏目名称列表
	 * @param news//新闻内容
	 * 
	 */
	public String imgnews(){
	    navChannels = indexService.getChannelsList(SysProperty.getPrep("hdnews_rootch"));
	    nav2Channels = new ArrayList<List<TChannels>>();
	    for (TChannels t : navChannels) {
            List<TChannels> temp = channelService.getLastChannels(t.getChannelId());
            nav2Channels.add(temp);
        }
	    news = newsService.getNewsByContentid(contentId);
	    newsTopChannel = newsService.getTchannelByNewsContentid(contentId);
	    channelsList = channelService.getChannels(newsTopChannel.getChannelId());
        leftTopChannel = channelService.getChannelById(newsTopChannel.getPreviousId());
        navOnChannelId=leftTopChannel.getChannelId();
		news.setResourceRids(newsService.getImgRids(news.getCid()));
		
		news.setResourceRid(indexService.getImgRid(news.getCid().toString()));
		return "ycimgnews";
	}
    @Override
	public void setServletContext(ServletContext arg0) {
		// TODO Auto-generated method stub
	}
	public NewsVo getNews() {
		return news;
	}
	public void setNews(NewsVo news) {
		this.news = news;
	}
    public List<TChannels> getNavChannels() {
        return navChannels;
    }
    public void setNavChannels(List<TChannels> navChannels) {
        this.navChannels = navChannels;
    }
    public List<TChannels> getChannelsList() {
        return channelsList;
    }
    public void setChannelsList(List<TChannels> channelsList) {
        this.channelsList = channelsList;
    }
    public String getChannelId() {
        return channelId;
    }
    public void setChannelId(String channelId) {
        this.channelId = channelId;
    }
    public String getContentId() {
        return contentId;
    }
    public void setContentId(String contentId) {
        this.contentId = contentId;
    }
    public TChannels getNewsTopChannel() {
        return newsTopChannel;
    }
    public void setNewsTopChannel(TChannels newsTopChannel) {
        this.newsTopChannel = newsTopChannel;
    }
    public TChannels getLeftTopChannel() {
        return leftTopChannel;
    }
    public void setLeftTopChannel(TChannels leftTopChannel) {
        this.leftTopChannel = leftTopChannel;
    }
    public List<List<TChannels>> getNav2Channels() {
        return nav2Channels;
    }
    public void setNav2Channels(List<List<TChannels>> nav2Channels) {
        this.nav2Channels = nav2Channels;
    }
    public String getNavOnChannelId() {
        return navOnChannelId;
    }
    public void setNavOnChannelId(String navOnChannelId) {
        this.navOnChannelId = navOnChannelId;
    }
}
